
// ArchWekx86Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "ArchWekx86.h"
#include "ArchWekx86Dlg.h"
#include "afxdialogex.h"
#include "MMXTest.h"
#include "CPUID.h"
#include "SSEExample2.h"
#include "SSEExample.h"
#include "SSE3Example.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CArchWekx86Dlg dialog




CArchWekx86Dlg::CArchWekx86Dlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CArchWekx86Dlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CArchWekx86Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BUTTON1, MMX_Button1);
	DDX_Control(pDX, IDC_BUTTON2, MMX_Button2);
	DDX_Control(pDX, IDC_EDIT1, Status_Edit);
	DDX_Control(pDX, IDC_BUTTON3, MMX_Button3);
	DDX_Control(pDX, IDC_BUTTON4, SSE_Button1);
	DDX_Control(pDX, IDC_BUTTON5, SSE_Button2);
	DDX_Control(pDX, IDC_BUTTON6, SSE_Button3);
	DDX_Control(pDX, IDC_BUTTON7, SSE2_Button1);
	DDX_Control(pDX, IDC_BUTTON8, SSE2_Button2);
	DDX_Control(pDX, IDC_BUTTON9, SSE2_Button3);
	DDX_Control(pDX, IDC_BUTTON10, SSE3_Button1);
	DDX_Control(pDX, IDC_BUTTON11, SSE3_Button2);
	DDX_Control(pDX, IDC_BUTTON12, SSE3_Button3);
	DDX_Control(pDX, IDC_PROGRESS1, NoOptProgress);
	DDX_Control(pDX, IDC_PROGRESS2, OptProgress);
}

BEGIN_MESSAGE_MAP(CArchWekx86Dlg, CDialogEx)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, &CArchWekx86Dlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CArchWekx86Dlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CArchWekx86Dlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CArchWekx86Dlg::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CArchWekx86Dlg::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CArchWekx86Dlg::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CArchWekx86Dlg::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CArchWekx86Dlg::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CArchWekx86Dlg::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON10, &CArchWekx86Dlg::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON11, &CArchWekx86Dlg::OnBnClickedButton11)
	ON_BN_CLICKED(IDC_BUTTON12, &CArchWekx86Dlg::OnBnClickedButton12)
END_MESSAGE_MAP()


// CArchWekx86Dlg message handlers

BOOL CArchWekx86Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	CPUID cpuid;
	cpuid.CheckExtension();
	CString cs=L"Wspierane rozszerzenia wektorowe x86:\r\n";
	cpuid.GetMMXSupport()?cs.Append(L"MMX:\t tak\r\n"):cs.Append(L"MMX:\t nie\r\n");
	cpuid.GetSSESupport()?cs.Append(L"SSE:\t tak\r\n"):cs.Append(L"SSE:\t nie\r\n");
	cpuid.GetSSE2Support()?cs.Append(L"SSE2:\t tak\r\n"):cs.Append(L"SSE2:\t nie\r\n");
	cpuid.GetSSE3Support()?cs.Append(L"SSE3:\t tak\r\n"):cs.Append(L"SSE3:\t nie\r\n");
	cpuid.GetSSSE3Support()?cs.Append(L"SSSE3:\t tak\r\n"):cs.Append(L"SSSE3:\t nie\r\n");
	cpuid.GetSSE41Support()?cs.Append(L"SSE4.1:\t tak\r\n"):cs.Append(L"SSE4.1:\t nie\r\n");
	cpuid.GetSSE42Support()?cs.Append(L"SSE4.2:\t tak\r\n"):cs.Append(L"SSE4.2:\t nie\r\n");
	cpuid.GetAESSupport()?cs.Append(L"AES:\t tak\r\n"):cs.Append(L"AES:\t nie\r\n");
	cpuid.GetAVXSupport()?cs.Append(L"AVX:\t tak\r\n"):cs.Append(L"AVX:\t nie\r\n");
	this->Status_Edit.SetWindowText(cs);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CArchWekx86Dlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CArchWekx86Dlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CArchWekx86Dlg::Lock()
{
	this->MMX_Button1.EnableWindow(false);
	this->MMX_Button2.EnableWindow(false);
	this->MMX_Button3.EnableWindow(false);
	this->SSE_Button1.EnableWindow(false);
	this->SSE_Button2.EnableWindow(false);
	this->SSE_Button3.EnableWindow(false);
	this->SSE2_Button1.EnableWindow(false);
	this->SSE2_Button2.EnableWindow(false);
	this->SSE2_Button3.EnableWindow(false);
	this->SSE3_Button1.EnableWindow(false);
	this->SSE3_Button2.EnableWindow(false);
	this->SSE3_Button3.EnableWindow(false);
	this->OptProgress.SetPos(0);
	this->NoOptProgress.SetPos(0);

}
void CArchWekx86Dlg::Unlock()
{
	this->MMX_Button1.EnableWindow(true);
	this->MMX_Button2.EnableWindow(true);
	this->MMX_Button3.EnableWindow(true);
	this->SSE_Button1.EnableWindow(true);
	this->SSE_Button2.EnableWindow(true);
	this->SSE_Button3.EnableWindow(true);
	this->SSE2_Button1.EnableWindow(true);
	this->SSE2_Button2.EnableWindow(true);
	this->SSE2_Button3.EnableWindow(true);
	this->SSE3_Button1.EnableWindow(true);
	this->SSE3_Button2.EnableWindow(true);
	this->SSE3_Button3.EnableWindow(true);
}
void CArchWekx86Dlg::CalculateView(int NoOpt, int Opt)
{
	if(NoOpt>=Opt)
	{
		this->NoOptProgress.SetRange32(0,NoOpt);
		this->OptProgress.SetRange32(0,NoOpt);
	}
	else
	{
		this->OptProgress.SetRange32(0,Opt);
		this->NoOptProgress.SetRange32(0,Opt);
	}
	this->OptProgress.SetPos(Opt);
	this->NoOptProgress.SetPos(NoOpt);
}
void CArchWekx86Dlg::OnBnClickedButton1()
{
	this->Lock();
	CImage image;
	image.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP1);
	MMXTest mmx;
	this->Status_Edit.SetWindowText(mmx.MMXExample1(image));
	this->CalculateView(mmx.GetTimeNoOpt(),mmx.GetTimeOpt());
	this->Unlock();
}


void CArchWekx86Dlg::OnBnClickedButton2()
{
	this->Lock();
	CImage image;
	image.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP1);
	MMXTest mmx;
	this->Status_Edit.SetWindowText(mmx.MMXExample2(image));
	this->CalculateView(mmx.GetTimeNoOpt(),mmx.GetTimeOpt());
	this->Unlock();
}


void CArchWekx86Dlg::OnBnClickedButton3()
{
	this->Lock();
	CImage image1,image2;
	image1.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP2);
	image2.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP3);
	MMXTest mmx;
	this->Status_Edit.SetWindowText(mmx.MMXExample3(image1,image2));
	this->CalculateView(mmx.GetTimeNoOpt(),mmx.GetTimeOpt());
	this->Unlock();
}


void CArchWekx86Dlg::OnBnClickedButton4()
{
	this->Lock();
	SSEExample sse;
	this->Status_Edit.SetWindowText(sse.example1(2.8f,10000000));
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}



void CArchWekx86Dlg::OnBnClickedButton5()
{
	this->Lock();
	SSEExample sse;
	this->Status_Edit.SetWindowText(sse.example2(5,200000,10000000));
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}


void CArchWekx86Dlg::OnBnClickedButton6()
{
	this->Lock();
	SSEExample sse;
	this->Status_Edit.SetWindowText(sse.example3(100,100));
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}


void CArchWekx86Dlg::OnBnClickedButton7()
{
	this->Lock();
	CImage image;
	image.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP4);
	SSEExample2 sse;
	this->Status_Edit.SetWindowText(sse.example1(image));
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}


void CArchWekx86Dlg::OnBnClickedButton8()
{
	this->Lock();
	SSEExample2 sse;
	this->Status_Edit.SetWindowText(sse.example2(400,400,400));
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}


void CArchWekx86Dlg::OnBnClickedButton9()
{
	this->Lock();
	SSEExample2 sse;
	this->Status_Edit.SetWindowText(sse.example3(5,200000,10000000));
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}


void CArchWekx86Dlg::OnBnClickedButton10()
{
	this->Lock();
	SSE3Example sse;
	this->Status_Edit.SetWindowText(sse.example1(100000));
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}

void CArchWekx86Dlg::OnBnClickedButton11()
{
	this->Lock();
	SSE3Example sse;
	this->Status_Edit.SetWindowText(sse.example2());
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}

void CArchWekx86Dlg::OnBnClickedButton12()
{
	this->Lock();
	CImage image,image2;
	image.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP2);
	image2.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP3);
	SSE3Example sse;
	this->Status_Edit.SetWindowText(sse.example3(image,image2));
	this->CalculateView(sse.GetTimeNoOpt(),sse.GetTimeOpt());
	this->Unlock();
}


